import React, { forwardRef, useRef } from "react";

const ForwardrefH3 = forwardRef((props, ref) => {
  return (
    <div>
      <h3 ref={ref}>123</h3>
    </div>
  );
});

export default () => {
  const h3El = useRef(null);
  return (
    <div>
      <ForwardrefH3 ref={h3El}></ForwardrefH3>
      <button
        onClick={(e) => {
          console.log(h3El);
          console.log(h3El.current); //DOM
        }}
      >
        查看h3 ref
      </button>
    </div>
  );
};
